﻿using System;
using System.Web.Mvc;
using MvcPrinciples.Logic;

namespace MvcPrinciples.Controllers
{
    public class PersonRewardController : Controller
    {
        public ActionResult Index(Guid id)
        {
			return View(DataProvider.GetStore.GetPersonRewards(id));
        }

        public ActionResult AddRersonReward()
        {
	        var personIdString = Request.QueryString["pid"];
			var rewardIdString = Request.QueryString["rid"];

			if (string.IsNullOrEmpty(personIdString) || string.IsNullOrEmpty(rewardIdString))
				return RedirectToAction("Index");

	        var pid = Guid.Parse(personIdString);
			var rid = Guid.Parse(rewardIdString);

	        DataProvider.GetStore.AddPersonReward(pid, rid);
			return RedirectToAction("Index", new { id = pid });
        }

		public ActionResult GetImage(Guid id, string type)
		{
			return File(Server.MapPath(string.Format("~/App_Data/{0}", id)), type);
		}
	}
}